<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="perm" uri="/WEB-INF/tld/perm.tld"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
	<script>var ctx="${ctx}";</script>
	<head>
	    <meta charset="utf-8">
	    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	    <title>货咖说管理</title>
	    <meta name="keycategorys" content="体验,友好,高级管理台,易用,高性能,高扩展性,bootstrap框架,响应式后台">
	    <meta name="description" content="这是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">
	    <meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
		<meta http-equiv="expires" content="Wed, 26 Feb 209908:21:57 GMT"> 
	    
		<link rel="shortcut icon" href="favicon.ico"> 
		<link href="${ctx}/static/css/bootstrap.min.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/font-awesome.min.css?v=4.4.0?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/footable/footable.core.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/summernote/summernote.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/summernote/summernote-bs3.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/iCheck/custom.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/chosen/chosen.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/animate.min.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/js/plugins/layer/laydate/laydate.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/webuploader/webuploader.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/style.min.css?v=${static_version}/" rel="stylesheet">
		<style type="text/css">
	       .color-red{color:#FF0000}
	       .color-red:hover{color:#FF0000;}
	       .color-red:visited{color:#FF0000;}
	       .color-red:active{color:#FF0000;}
	       .color-red:link{color:#FF0000;}
	    </style>
	</head>
	<body class="gray-bg">
    	<div class="ibox float-e-margins">
    		<div class="ibox-content">
                <form class="form-group" style="margin-left:20px;margin-right:20px" id="discuss_table_form">	
                	<input type="hidden" id="pageSize" name="pageSize" value="15">
                	<input type="hidden" id="pageIndex" name="pageIndex" value="1">
                	<input type="hidden" id="discuss-categoryId" name="categoryId" value="">
                	<div class="row">
                		<perm:hasPermission code="discuss/find">
                        <div class="col-md-2"><input name="keyword" type="text" placeholder="请输入关键字" class="form-control" /></div>
		     	  		<div class="col-md-4">
                            <div class="input-daterange input-group">
                                <input id="startTime" type="text" class="input-md form-control layer-date" placeholder="开始时间"  name="startTime">
					        	<span class="input-group-addon">至</span>
					        	<input id="endTime" type="text" class="input-md form-control layer-date" placeholder="结束时间"  name="endTime">
                            </div>
					    </div>
					    <div class="col-md-2 col-sm-2">
							<select data-placeholder="选择栏目" id="discuss-category" class="input-md form-control chosen-select" tabindex="4">
			                    <option value="">请选栏目</option>
			                </select>
						</div>
						<div class="col-md-1 col-sm-2">
							<button id="discuss_table_search" type="button" class="btn btn-outline btn-block btn-primary">查询</button>
						</div>
						</perm:hasPermission>
						<perm:hasPermission code="discuss/categoryIndex">
					    <div class="col-md-1  col-sm-2 pull-right ">
							<a  onclick="clickDiscussCategoryListGet()" class="btn btn-block btn-outline btn-primary">类目维护</a>
					    </div>
					    </perm:hasPermission>
					    <perm:hasPermission code="discuss/wordIndex">
					    <div class="col-md-2  col-sm-3 pull-right ">
							<a  onclick="clickDiscussWordListGet()" class="btn btn-block btn-outline btn-primary">停用词维护</a>
					    </div>
					    </perm:hasPermission>
                    </div>
                </form>
    			<div class="ibox-content">
                   <div class="social-feed-separated" id="discuss_table"></div>
                  <div class="row">
			  		<div class="col-md-6" class="pull-left" id="page_left_text_dis"></div>
			  		<div class="col-md-6"  id="page_text_dis"></div>
			     </div>
            </div>
		</div>
	</div>
		
	<script src="${ctx}/static/js/jquery.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/bootstrap.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/footable/footable.all.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/validate/jquery.validate.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/validate/messages_zh.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/webuploader/webuploader.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/summernote/summernote.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/summernote/summernote-zh-CN.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/chosen/chosen.jquery.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/layer/laydate/laydate.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/iCheck/icheck.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/plugins/laypage/laypage.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/switchery/switchery.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/eModal.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/cookie.js?v=?v=${static_version}"></script>
	<script src="${ctx}/static/common/custom-datatable.js?v=${static_version}"></script>
	<script src="${ctx}/static/common/custom-table.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/content.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/contabs.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/common/common.js?v=${static_version}"></script>
	
	<script>
	
	function serializeObject(obj, aoData) {
        var a = obj.serializeArray();
        $.each(a,
        function() {
            aoData[this.name] = this.value || ""
        });
        return aoData
    }
	
	var retrieveData=function(){
		
		var aoData = serializeObject($("#discuss_table_form"), {});
		
		$.ajax({  
			url:'${ctx}/discuss/find',  
			data:aoData,   
			type: 'POST',
				dataType:'json',  
				success:function(response){
					if(response.code==0){
						laypage({
			                cont: "page_text_dis",
			                skip: true,
			                skin: 'molv',
			                pages: response.data.totalPages,
			                prev: '<',
			                next: '>',
			                first: 1,
			                pageNum:response.data.pageSize,
			                last: response.data.totalPages,
			                curr: response.data.page,
			                jump: function(obj,first) {
			                	if(!first){ //点击跳页触发函数自身，并传递当前页：obj.curr
			                		$("#pageIndex").val(obj.curr);
			                		$("#pageIndex").val(obj.everyPage);
			                         retrieveData(obj.curr,obj.everyPage)
			                    }
			                }
			            });
						var page=response.data;
						if (page.totalCount > 0) {
			            	$("#page_left_text_dis").show();
			                $("#page_left_text_dis").html("当前显示第<strong>&nbsp;" + (((page.page - 1) * page.pageSize) + 1) + "&nbsp;</strong>到<strong>&nbsp;" + ((page.page) * page.pageSize > page.totalCount ? page.totalCount: (page.page) * page.pageSize) + "&nbsp;</strong>条,&nbsp;共计<strong>&nbsp;" + page.totalCount + "&nbsp;</strong>条<strong>&nbsp;" + page.totalPages + "&nbsp;</strong>页")
			            }else{
			            	$("#page_left_text_dis").hide();
			            }
						var data=response.data.data;
						var html = [];
						
						for(var j=0;j<data.length;j++){
							var discusses=data[j]
							var id=discusses.id;
							var answers=discusses.answers;
							
							html.push('<div class="social-avatar" id="'+id+'-social-avatar">');
							html.push('<a href="">');
							html.push('<img class="feed-photo"  alt="image" src="'+discusses.createHeadImg+'">');
							html.push('</a>');
							html.push('</div>');
							html.push('<div class="social-feed-box" id="'+id+'-social-feed-box">');
							html.push('<div class="pull-right"  style="margin-top:15px;margin-right:15px;" >');
							html.push('<a  href="javascript:;" class="btn btn-outline btn-xs btn-primary" data-id="'+id+'" data-answers-id="'+discusses.id+'" data-answers-user-id="'+discusses.createUser+'" onclick="replaceWordHtml(this,1)" style="margin-left:5px;">停用词过滤</a>');
							html.push('<a  href="javascript:;" class="btn btn-outline btn-xs btn-primary" data-id="'+id+'" data-answers-id="'+discusses.id+'" data-answers-user-id="'+discusses.createUser+'" onclick="replaceWordHtml(this,2)" style="margin-left:5px;">反向过滤停用词</a>');
			                html.push('<a  href="javascript:;" class="btn btn-outline btn-xs btn-primary" data-id="'+id+'" data-answers-id="'+discusses.id+'" data-answers-user-id="'+discusses.createUser+'" onclick="insertQunestionHtml(this)" style="margin-left:5px;">修改</a>');
			                html.push('<a  href="javascript:;" class="btn btn-outline btn-xs btn-primary" onclick="deleteDiscuss(this,1)" data-discusses-id="'+discusses.id+'" data-url="${ctx}/discuss/delete"  style="margin-left:5px;">删除</a>');
			                html.push('<a  href="javascript:;" class="btn btn-outline btn-xs btn-primary" data-id="'+id+'" data-answers-id="'+discusses.id+'" data-answers-user-id="'+discusses.createUser+'" onclick="insertAnswerHtml(this)" style="margin-left:5px;">评论</a>');
			                html.push('<a  href="javascript:;" class="btn btn-outline btn-xs btn-primary" style="margin-left:5px;" onclick="clickDiscussInfoGet(this)" data-id="'+id+'">详情</a>');
			                html.push('</div>');
							html.push('<div class="social-avatar">');
							html.push('<a  href="javascript:;" >'+discusses.createUsername+'</a>');
							html.push('<span style="margin-left:10px;" class="text-muted">'+discusses.categoryName+'</span>');
							html.push('<span style="margin-left:10px;" data-type="datetime"class="text-muted">'+discusses.createTime+'</span>');
							html.push('</div>');
							html.push('<div id="'+id+'-social-body" class="social-body">');
							html.push('<p>'+discusses.content+'</p>');
							
							if(discusses.img){
								var imgs=[];
								if(discusses.img.indexOf("|")>=0){
									imgs=discusses.img.split("|");
								}else{
									imgs.push(discusses.img);
								}
								html.push('<div class="photos">');
								for(var i=0;i<imgs.length;i++){
									html.push('<a target="_blank" href="'+imgs[i]+'">');
						            html.push('<img alt="image" class="feed-photo" src="'+imgs[i]+'">');
						            html.push('</a>');
								}
				                html.push('</div>');
							}
							html.push('</div>');
							
							html.push('<div id="'+id+'-social-footer" class="social-footer">');
				            for(var i=0;i<answers.length;i++){
				            	var row=answers[i];
				            	html.push('<div class="social-comment" id="'+row.id+'-social-comment">');
				                html.push('<a  href="javascript:;"  class="pull-left">');
				                html.push('<img alt="image" src="'+row.createHeadImg+'">');
				                html.push('</a>');
				                html.push('<div class="media-body">');
				                html.push('<a  href="javascript:;" >'+row.createUsername+'</a>');
				                if(row.type==1){
				                	html.push('<a style="color:red;" href="javascript:;" >(管理用户)</a>');
				                }
				                if(row.replyUsername){
				                	 html.push('<span style="margin-left:5px;">回复</span>');
				                	 html.push('<a  href="javascript:;"  style="margin-left:5px;">'+row.replyUsername+'</a>');
				                }
				                html.push('<div class="pull-right">');
				                html.push('<a  href="javascript:;" class="btn btn-outline btn-xs btn-primary" data-id="'+id+'" data-answers-id="'+row.id+'" data-answers-user-id="'+row.createUser+'" onclick="replaceAnswerWordHtml(this,1)" style="margin-left:5px;">停用词过滤</a>');
								html.push('<a  href="javascript:;" class="btn btn-outline btn-xs btn-primary" data-id="'+id+'" data-answers-id="'+row.id+'" data-answers-user-id="'+row.createUser+'" onclick="replaceAnswerWordHtml(this,2)" style="margin-left:5px;">反向过滤停用词</a>');
				                html.push('<a  href="javascript:;" class="btn btn-outline btn-xs btn-primary" data-id="'+id+'" data-answers-id="'+row.id+'" data-answers-user-id="'+row.createUser+'" onclick="updateAnswerHtml(this)" style="margin-left:5px;">修改</a>');
								html.push('<a  href="javascript:;"  onclick="deleteDiscuss(this,2)" data-url="${ctx}/discuss/deleteAnswers" data-id="'+row.id+'"  data-answers-id="'+row.id+'" data-answers-user-id="'+row.createUser+'" style="margin-left:5px;" class="btn btn-outline btn-xs btn-primary" >删除</a>');
				                html.push('<a  href="javascript:;"  onclick="insertReplyHtml(this)" data-id="'+row.id+'" style="margin-left:3px;" data-answers-id="'+row.id+'" data-answers-user-id="'+row.createUser+'" class="btn btn-outline btn-xs btn-primary">回复</a>');
				                if(!discusses.pretyAnswer){
				                	html.push('<a  href="javascript:;"  data-discuss-id="'+id+'" data-id="'+row.id+'" onclick="updatePrettyAnswer(this)" style="margin-left:3px;" data-answers-id="'+row.id+'" data-answers-user-id="'+row.createUser+'" class="btn btn-outline btn-xs btn-primary prety-answer">最佳答案</a>');
				                }
				                html.push('</div>');
				                html.push('<span id="'+row.id+'-content" style="margin-left:10px;">');
				                html.push( row.content);
				                html.push('</span>');
				                html.push('<br/>');
				                html.push('<div data-id="'+row.id+'" id="'+row.id+'-prety-answer">');
				                
				                html.push('<a href="javascript:;" onclick="updateAnswers(this,1)" data-id="'+row.id+'" data-num="'+row.upClick+'"');
				                if(row.upUserClick){
				                	html.push(' class="small color-red" data-persent="-1" ');
				                }else{
				                	html.push(' class="small" data-persent="1" ');
				                }
				                html.push('><i class="fa fa-thumbs-up"></i>'+row.upClick+'</a>');
				                
				                html.push('<a href="javascript:;" onclick="updateAnswers(this,2)" data-id="'+row.id+'" style="margin-left:10px"  data-num="'+row.upClick+'"');
				                if(row.downUserClick){
				                	html.push(' class="small color-red" data-persent="-1" ');
				                }else{
				                	html.push(' class="small" data-persent="1" ');
				                }
				                html.push('><i class="fa fa-thumbs-down"></i>'+row.downClick+'</a>');
				                
				                if(discusses.pretyAnswer==row.id){
				                	html.push('<a style="margin-left:10px"  href="javascript:;"  class="small">最佳答案</a>');
				                }
				                html.push('<span class="text-muted"  style="margin-left:10px"  data-type="datetime">'+row.createTime+'</span>');
				                html.push('</div>');
				                html.push('</div>');
				                html.push('</div>');
				            }
				            html.push('</div></div>');
						}
						$("#discuss_table").html(html.join(""));
						
						dataFormater("#discuss_table");
						
					}else{
					    $.confirm({cancelButton: "关   闭",title: '提示!',content: "添加货咖说错误!"});
					}
				}  
		    }); 
		}
	
		var dataFormater=function(id){
			$(id).find("[data-type=datetime]").each(function () {
				var formater= jQuery(this).data('formater');
				if(formater==undefined || formater==''){
					formater="yyyy-MM-dd HH:mm:ss";
				}
				var text = jQuery(this).text();
			    if(text==undefined || text==''){
					jQuery(this).text("");
					return;
				}
				jQuery(this).text(new Date(Number(text)).format(formater))
			 });
		};
	
		/**
		* 更新点赞和非点赞
		*/
		var updateAnswers=function(me,isUp){
			var persent=$(me).data("persent");
	        var id=$(me).data("id");
			var num=(Number($(me).data("num"))+Number(persent));
			
			$.ajax({  
				url:'${ctx}/discuss/updateAnswers',  
				data:{
					"isUp":isUp,
					"persent":persent,
					"id":id	
				},   
				type: 'POST',
				dataType:'json',  
				success:function(response){
					if(response.code==0){
						var html="";
						$(me).data("num",num);
						if(isUp==1){
							html='<i class="fa fa-thumbs-up"></i>'+num;
						}else{
							html='<i class="fa fa-thumbs-down"></i>'+num;
						}
						if(persent==1){
							$(me).addClass("color-red");
							$(me).data("persent","-1");
						}else{
							$(me).removeClass("color-red");
							$(me).data("persent","1");
						}
						$(me).html(html);
					}else if(response.code==2){//已经点赞/或者拍砖
						 
					}else{
						 $.confirm({cancelButton: "关   闭",title: '提示!',content: "保存角色权限错误!"||"保存数据错误!"});
					}
				}  
		    });
		}
		
		/**
		* 更新最佳答案
		*/
		var updatePrettyAnswer=function(me){
	        var id=$(me).data("id");
	        var discussId=$(me).data("discuss-id");
			$.ajax({  
				url:'${ctx}/discuss/update',  
				data:{
					"pretyAnswer":id,
					"id":discussId	
				},   
				type: 'POST',
				dataType:'json',  
				success:function(response){
					if(response.code==0){
						var html='<a style="margin-left:10px"  href="javascript:;"  class="small">最佳答案</a>';
						$("#"+id+"-prety-answer span").after(html);
						$("#"+discussId+"-social-footer"+" a.prety-answer").remove();
					}else{
					    $.confirm({cancelButton: "关   闭",title: '提示!',content: "保存角色权限错误!"||"保存数据错误!"});
					}
				}  
		    });
		}
		
		var deleteDiscuss=function(me,type){
			$.confirm({
			    text: $(me).data("title")||"确定删除这条数据么?",
			    confirm: function() {
			    	$.ajax({  
						url:$(me).data("url"),  
						data:{
							id:$(me).data("id"),	
						},   
						type: 'POST',
						dataType:'json',  
						success:function(response){
							if(response.code==0){
								if(type==1){
						    		var discussesId=$(me).data("discusses-id");
						    		$("#"+discussesId+"-social-avatar").remove();
						    		$("#"+discussesId+"-social-feed-box").remove();
						    		$("#"+discussesId+"-social-avatar-info").remove();
						    		$("#"+discussesId+"-social-feed-box-info").remove();
						    	}else{
						    		var anwserId=$(me).data("id");
						    		$("#"+anwserId+"-social-comment-info").remove();
						    	}
								return true;
							}else{
							    $.confirm({cancelButton: "关   闭",title: '提示!',content: (me).data("title")+"错误!"||"删除数据错误!"});
							}
							return false;
						}  
				    }); 
			    },
			    cancel: function() {
			        return true;
			    }
			});
		}
	
		/**
		* 评论货咖说
		*/
		var insertAnswerHtml=function(me,info){
			if($("#"+$(me).data("id")+"-social-footer").find("textarea").length<=0 || $("#"+$(me).data("id")+"-social-footer-info").find("textarea").length<=0){
				var html=[];
				html.push('<div data-id="'+$(me).data("id")+'" data-answers-id="'+$(me).data("answers-id")+'" data-answers-user-id="'+$(me).data("answers-user-id")+'" class="media-body" style="margin-top:3px" >');
	            html.push('<textarea class="form-control" placeholder="填写评论/回复..."></textarea>');
	            html.push('<div style="display:inline-block;margin-top:3px">');
	            html.push('<button id="sysUser_table_search" style="width:50px" onclick="saveReplyHtml(this,2)" class="btn btn-outline btn-xs btn-primary">保存</button>');
	            html.push('<button id="sysUser_table_search2" style="width:50px;margin-left:10px" onclick="removeReplyHtml(this)" type="button" class="btn btn-outline btn-xs btn-primary">取消</button>');
	            html.push('</div>');
	            html.push('</div>');
	            var obj=$(html.join(""));
	            $("#"+$(me).data("id")+"-social-footer").prepend(obj);
	            $("#"+$(me).data("id")+"-social-footer-info").prepend(obj);
	            $(obj).find("textarea").focus();
			}
		}
	
		/**
		* 回复评论
		*/
		var insertReplyHtml=function(me){
			if($(me).parent().parent().parent().find("textarea").length<=0){
				var html=[];
				html.push('<div  data-id="'+$(me).data("id")+'" data-answers-id="'+$(me).data("answers-id")+'" data-answers-user-id="'+$(me).data("answers-user-id")+'" class="media-body" style="margin-top:3px" >');
	            html.push('<textarea class="form-control" placeholder="填写评论/回复..."></textarea>');
	            html.push('<div style="display:inline-block;margin-top:3px">');
	            html.push('<button id="sysUser_table_search" style="width:50px" onclick="saveReplyHtml(this,3)" class="btn btn-outline btn-xs btn-primary">保存</button>');
	            html.push('<button id="sysUser_table_search2" style="width:50px;margin-left:10px" onclick="removeReplyHtml(this)" type="button" class="btn btn-outline btn-xs btn-primary">取消</button>');
	            html.push('</div>');
	            html.push('</div>');
	            var obj=$(html.join(""));
	            $(me).parent().parent().append(obj);
	            $(obj).find("textarea").focus();
			}
		}
		
		var replaceWordHtml =function(me,unReplace,info){
			
			iframeReload("/magic-cloud-manage/discuss/index");
			
			/*
			if($("#"+$(me).data("id")+"-social-body"+(info||'')+" textarea").length<=0){
				var target=$("#"+$(me).data("id")+"-social-body"+" p");
				$.ajax({  
 					url:'${ctx}/discuss/wordReplace',  
 					data:{
						content:target.html(),	
						unReplace:unReplace,
						id:$(me).data("id")
					},   
					type: 'POST',
 					dataType:'json',  
 					success:function(response){
 						if(response.code==0){
 							var html=[];
 							html.push('<div data-id="'+$(me).data("id")+'"  data-answers-id="'+$(me).data("answers-id")+'" data-answers-user-id="'+$(me).data("answers-user-id")+'" class="media-body" style="margin-top:3px" >');
 				            html.push('<textarea class="form-control" placeholder="填写评论/回复..." >'+response.data+'</textarea>');
 				            html.push('<div style="display:inline-block;margin-top:3px">');
 				            html.push('<button id="sysUser_table_search" style="width:50px" onclick="saveReplyHtml(this,1)" class="btn btn-outline btn-xs btn-primary">保存</button>');
 				            html.push('<button id="sysUser_table_search2" style="width:50px;margin-left:10px" onclick="removeReplyHtml(this)" type="button" class="btn btn-outline btn-xs btn-primary">取消</button>');
 				            html.push('</div>');
 				            html.push('</div>');
 				            var obj=$(html.join(""));
 				            $("#"+$(me).data("id")+"-social-body p").after(obj);
 				            $("#"+$(me).data("id")+"-social-body-info p").after(obj);
 				            $(obj).find("textarea").focus();
 						}else{
 						    $.confirm({cancelButton: "关   闭",title: '提示!',content: "添加货咖说停用词错误!"});
 						}
 					}  
 			    });
			}
			*/
		}
		
		var replaceAnswerWordHtml =function(me,unReplace,info){
			if($(me).parent().parent().parent().find("textarea").length<=0){
				var target=$("#"+$(me).data("answers-id")+"-content");
				$.ajax({  
 					url:'${ctx}/discuss/wordReplace',  
 					data:{
						content:target.html(),	
						unReplace:unReplace,
						id:$(me).data("id")
					},   
					type: 'POST',
 					dataType:'json',  
 					success:function(response){
 						if(response.code==0){
 							var html=[];
 							html.push('<div data-id="'+$(me).data("answers-id")+'"  data-answers-id="'+$(me).data("answers-id")+'" data-answers-user-id="'+$(me).data("answers-user-id")+'" class="media-body" style="margin-top:3px" >');
 				            html.push('<textarea class="form-control" placeholder="填写评论/回复..." >'+response.data+'</textarea>');
 				            html.push('<div style="display:inline-block;margin-top:3px">');
 				            html.push('<button id="sysUser_table_search" style="width:50px" onclick="saveReplyHtml(this,4)" class="btn btn-outline btn-xs btn-primary">保存</button>');
 				            html.push('<button id="sysUser_table_search2" style="width:50px;margin-left:10px" onclick="removeReplyHtml(this)" type="button" class="btn btn-outline btn-xs btn-primary">取消</button>');
 				            html.push('</div>');
 				            html.push('</div>');
 				            var obj=$(html.join(""));
 				            target.after(obj);
 				            $(obj).find("textarea").focus();
 						}else{
 						    $.confirm({cancelButton: "关   闭",title: '提示!',content: "添加货咖说停用词错误!"});
 						}
 					}  
 			    });
			}
		}
		
		/**
		* 修改评论/回复
		*/
		var updateAnswerHtml=function(me,info){
			cons
			if($(me).parent().parent().parent().find("textarea").length<=0){
				var html=[];
				var target=$("#"+$(me).data("answers-id")+"-content");
				html.push('<div data-id="'+$(me).data("answers-id")+'"  data-answers-id="'+$(me).data("answers-id")+'" data-answers-user-id="'+$(me).data("answers-user-id")+'" class="media-body" style="margin-top:3px" >');
	            html.push('<textarea class="form-control" placeholder="填写评论/回复..." >'+target.html()+'</textarea>');
	            html.push('<div style="display:inline-block;margin-top:3px">');
	            html.push('<button id="sysUser_table_search" style="width:50px" onclick="saveReplyHtml(this,4)" class="btn btn-outline btn-xs btn-primary">保存</button>');
	            html.push('<button id="sysUser_table_search2" style="width:50px;margin-left:10px" onclick="removeReplyHtml(this)" type="button" class="btn btn-outline btn-xs btn-primary">取消</button>');
	            html.push('</div>');
	            html.push('</div>');
	            var obj=$(html.join(""));
	            target.after(obj);
	            $(obj).find("textarea").focus();
			}
		}
		
		/**
		* 修改货咖说
		*/
		var insertQunestionHtml=function(me,info){
			if($("#"+$(me).data("id")+"-social-body"+(info||'')+" textarea").length<=0){
				var html=[];
				var target=$("#"+$(me).data("id")+"-social-body"+" p");
				html.push('<div data-id="'+$(me).data("id")+'"  data-answers-id="'+$(me).data("answers-id")+'" data-answers-user-id="'+$(me).data("answers-user-id")+'" class="media-body" style="margin-top:3px" >');
	            html.push('<textarea class="form-control" placeholder="填写评论/回复..." >'+target.html()+'</textarea>');
	            html.push('<div style="display:inline-block;margin-top:3px">');
	            html.push('<button id="sysUser_table_search" style="width:50px" onclick="saveReplyHtml(this,1)" class="btn btn-outline btn-xs btn-primary">保存</button>');
	            html.push('<button id="sysUser_table_search2" style="width:50px;margin-left:10px" onclick="removeReplyHtml(this)" type="button" class="btn btn-outline btn-xs btn-primary">取消</button>');
	            html.push('</div>');
	            html.push('</div>');
	            var obj=$(html.join(""));
	            $("#"+$(me).data("id")+"-social-body p").after(obj);
	            $("#"+$(me).data("id")+"-social-body-info p").after(obj);
	            $(obj).find("textarea").focus();
			}
		}
		
		var saveReplyHtml=function(me,type){
			var target=$(me).parent().parent();
			var replyHtml=target.find("textarea").val();
	        var replyUser=target.data("answers-user-id");
	        var id=target.data("id");
	        var answersId=target.data("answers-id");
			if(type==1){//修改货咖说
				$.ajax({  
					url:'${ctx}/discuss/update',  
					data:{
						"content":replyHtml,	
						"id":id	
					},   
					type: 'POST',
					dataType:'json',  
					success:function(response){
						if(response.code==0){
							target.find("textarea").val(replyHtml);
							removeReplyHtml(me);
						}else{
						    $.confirm({cancelButton: "关   闭",title: '提示!',content: "保存角色权限错误!"||"保存数据错误!"});
						}
					}  
			    }); 
			}else if(type==2){//评论
				$.ajax({  
					url:'${ctx}/discuss/addAnswers',  
					data:{
						"content":replyHtml,	
						"discussId":id	
					},   
					type: 'POST',
					dataType:'json',  
					success:function(response){
						if(response.code==0){
							removeReplyHtml(me);
						}else{
						    $.confirm({cancelButton: "关   闭",title: '提示!',content: "保存角色权限错误!"||"保存数据错误!"});
						}
					}  
			    });  
			}else if(type==3){//回复
				$.ajax({  
					url:'${ctx}/discuss/addAnswers',  
					data:{
						"content":replyHtml,
						"replyUser":replyUser,
						"replyId":id,
						"discussId":id	
					},   
					type: 'POST',
					dataType:'json',  
					success:function(response){
						if(response.code==0){
							removeReplyHtml(me);
						}else{
						    $.confirm({cancelButton: "关   闭",title: '提示!',content: "保存角色权限错误!"||"保存数据错误!"});
						}
					}  
			    });  
			}else if(type==4){//修改评论/回复
				$.ajax({  
					url:'${ctx}/discuss/updateAnswerContent',  
					data:{
						"content":replyHtml,	
						"id":id	
					},   
					type: 'POST',
					dataType:'json',  
					success:function(response){
						if(response.code==0){
							$("#"+id+"-content").html(replyHtml);
							removeReplyHtml(me);
						}else{
						    $.confirm({cancelButton: "关   闭",title: '提示!',content: "保存角色权限错误!"||"保存数据错误!"});
						}
					}  
			    }); 
			}
		}
		
		var removeReplyHtml=function(me){
	        $(me).parent().parent().remove();
		}
		
		$(function(){
		
			jQuery.searchFormInit();
			
			$("#discuss_table_search").on("click",function() {
	            retrieveData();
	        });
			
			retrieveData();
		
		});
		
		var clickDiscussInfoGet=function(me){
			eModal.ajax({
	   	        url: "${ctx}/discuss/info?id="+$(me).data("id"),
	   	        title:'查看货咖说详情',
	   	        loading:true,
	   	        size: eModal.size.xl,
	   	        subtitle: '',
	   	        buttons: [{text: '取消', style: 'danger', close: false, click:function(){
   	            		eModal.close();
   	            	}}
	   	        ],
	   	    });
			return false;
		}
		
		var clickDiscussWordListGet=function(me){
			eModal.ajax({
	   	        url: "${ctx}/discuss/wordIndex",
	   	        title:'货咖说停用词列表',
	   	        loading:true,
	   	        size: eModal.size.xl,
	   	        subtitle: '',
	   	        buttons: [{text: '取消', style: 'danger', close: false, click:function(){
   	            		eModal.close();
   	            	}}
	   	        ],
	   	    });
			return false;
		}
		
		var clickDiscussCategoryListGet=function(me){
			eModal.ajax({
	   	        url: "${ctx}/discuss/categoryIndex",
	   	        title:'货咖说类目列表',
	   	        loading:true,
	   	        size: eModal.size.xl,
	   	        subtitle: '',
	   	        buttons: [{text: '取消', style: 'danger', close: false, click:function(){
   	            		eModal.close();
   	            	}}
	   	        ],
	   	    });
			return false;
		}
		
		$.ajax({  
			url:'${ctx}/discuss/categoryFind',  		 					
			type: 'POST',
			dataType:'json',  
			data:{"status":1},
			success:function(response){
				if(response.code==0){
					var html=[];
					var data=response.data||[];
					for(var i=0;i<data.length;i++){
						html.push('<option value="'+data[i].id+'">'+data[i].lable+'</option>');
					}
					$("#discuss-category").append(html.join(""));
					$("#discuss-category").trigger("chosen:updated");
				}
			 }  
	     });
		
		
		 $("#discuss-category").chosen({width:'100%'}).change(function(event) {
			$("#discuss-categoryId").val($(event.target).val());
		 });
		
	</script>
	
	</body>
</html>